<?php
require_once "ModelBase.php";
class Term extends TTEvent_Table_Abstract
{
	protected $_name = 'tamtay_term';
	protected $_primary = 'tid';
	
	
	public function get($tid){

		$sql = "SELECT * FROM tamtay_term WHERE tid=?";
		$db = $this->getSlaveDB();
		$rs = $db->query($sql, $tid);
		return $rs->fetch();
	}
	
	public function getTermOfType($type){
		//return $this->fetchAllWhere(array('type'=>$type));
		$sql = "SELECT * FROM tamtay_term WHERE type='".$type."'";
		return $this->execSelectQuery($sql);
	}
	
	public function getTermOfEvent(){
		//return $this->fetchAllWhere(array('type'=>$type));
		$sql = "SELECT tid as category_id, name as category_name, 0 as forum_promoted  FROM tamtay_term WHERE type='event'";
		return $this->execSelectQuery($sql);
	}
	
	public function getAll(){
		$sql = "SELECT * FROM tamtay_term";
		return $this->execSelectQuery($sql);
	}
	
	public function getTermEventList($tid, $page=0, $limit=20){
		$sql = "SELECT * FROM tamtay_event WHERE cid=? ORDER BY changed DESC";
		$this->setRowPerPage($limit);
		return $this->pageQuery($sql, array($tid), $page);
	}
}

